<!--
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->

<div class="users-pane">
  <div class="clearfix">
    <ol class="breadcrumb pull-left">
      <li class="active">{{clusterId}} {{'common.roles' | translate}}</li>
    </ol>
  </div>
  <hr>
  <div class="pull-right">
    <div class="layout-switch-icon-wrapper disabled">
      <i class="glyphicon glyphicon-th-large layout-switch-icon" ng-click="switchToBlock()" tooltip-html-unsafe="{{'clusters.switchToBlock' | translate}}"></i>
      <p class="label-block">{{'common.blockViewLabel' | translate}}</p>
    </div>
    <div class="layout-switch-icon-wrapper">
      <i class="glyphicon glyphicon-list layout-switch-icon"></i>
      <p class="label-list">{{'common.listViewLabel' | translate}}</p>
    </div>
  </div>
  <ul class="nav nav-pills">
    <li ng-class="{'active': isUserActive}"><a ng-click="switchToUser()">{{'common.users' | translate}}</a></li>
    <li ng-class="{'active': !isUserActive}"><a ng-click="switchToGroup()">{{'common.groups' | translate}}</a></li>
  </ul>
  <br/>
  <table class="table table-striped table-hover">
    <thead>
    <tr>
      <th class="role-name-column">
        <div class="search-container">
          <label for="">{{'common.name' | translate}}</label>
          <input type="text" class="form-control namefilter" placeholder="{{'common.any' | translate}}" ng-model="currentNameFilter" ng-change="resetPagination()">
          <button type="button" class="close clearfilter" ng-show="currentNameFilter" ng-click="currentNameFilter=''; resetPagination()">
            <span aria-hidden="true">&times;</span><span class="sr-only">{{'common.controls.close' | translate}}</span>
          </button>
        </div>
      </th>
      <th>
        <label for="">{{'clusters.role' | translate}}</label>&nbsp;
        <i class="glyphicon glyphicon-question-sign green-icon cursor-pointer" ng-click="showHelpPage()"></i>
        <select class="form-control statusfilter"
                ng-model="currentRoleFilter"
                ng-options="item.label for item in roleFilterOptions"
                ng-change="resetPagination()">
        </select>
      </th>
    </tr>
    </thead>
    <tbody>
    <tr ng-repeat="user in users">
      <td>
        <a href="#/{{user.url}}">{{user.principal_name}}</a>
      </td>
      <td>
        <div ng-show="!user.editable">{{user.permission_label}}</div>
        <select class="form-control role-select" ng-show="user.editable" ng-model="user.permission_name"
                ng-options="role.permission_name as role.permission_label for role in roleValueOptions">
        </select>
        <span ng-show="user.principal_type != $parent.currentTypeFilter.value">&nbsp;{{'common.fromGroupMark' | translate}}</span>
        <span ng-show="user.permission_name != user.original_perm">
          <button class="btn btn-default btn-xs cancel" ng-click="cancel(user)">
            <span class="glyphicon glyphicon-remove cancel"></span>
          </button>
          <button class="btn btn-primary btn-xs" ng-click="save(user)">
            <span class="glyphicon glyphicon-ok"></span>
          </button>
        </span>
      </td>
    </tr>
    </tbody>
  </table>
  <div class="alert alert-info col-sm-12" ng-show="!users.length">
    {{'common.alerts.nothingToDisplay' | translate: '{term: (isUserActive ? constants.users : constants.groups)}'}}
  </div>
  <div class="col-sm-12 table-bar">
    <div class="pull-left filtered-info">
      <span>{{'common.filterInfo' | translate: '{showed: tableInfo.showed, total: tableInfo.total, term: (isUserActive ? constants.users : constants.groups)}'}}</span>
      <span ng-show="isNotEmptyFilter">- <a href ng-click="clearFilters()">{{'common.controls.clearFilters' | translate}}</a></span>
    </div>
    <div class="pull-right left-margin">
      <pagination class="paginator" total-items="totalUsers" max-size="maxVisiblePages" items-per-page="usersPerPage" ng-model="currentPage" ng-change="pageChanged()"></pagination>
    </div>
    <div class="pull-right">
      <select class="form-control" ng-model="usersPerPage" ng-change="usersPerPageChanges()" ng-options="currOption for currOption in [10, 25, 50, 100]"></select>
    </div>
  </div>
</div>
